﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;

namespace QFlow.Core
{
    [ProvideProperty("PermissionName", typeof(Control))]
    public class SecurePanel : Component, IExtenderProvider
    {
        public SecurePanel()
        {
            InitializeComponent();
            if (!this.DesignMode)
            {
                foreach (var permission in permissions)
                {
                    permission.Key.Visible = Authentication.HasPermission(permission.Value);
                }
            }
        }
        private Dictionary<Control, string> permissions = new Dictionary<Control, string>();

        #region IExtenderProvider Members

        public bool CanExtend(object extendee)
        {
            if (extendee is Panel)
                return true;
            return false;
        }

        #endregion

        public string GetPermissionName(Control control)
        {
            if (permissions.ContainsKey(control))
                return permissions[control];
            else return string.Empty;

        }

        public void SetPermissionName(Control control, string permissionName)
        {
            permissions.Add(control, permissionName);
        }

        private void InitializeComponent()
        {

        }
    }
}
